﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PPI.Data.Inspection;
using PPI.Entities.Inspections;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic.Inspections  
{
    public class LNote : IMobileTable
    {
        public static DataSet SelectAllIdName(string connectionKey)
        {
            return DInspectionNote.SelectAllIdName(connectionKey);
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery("Delete tb_Notes"));
            DataTable dt = SelectAllIdName(connectionKey).Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                //dr["Inspection_NodeId"]
                //dr["Name"]
                listQueries.Add(new EMobileQuery("Insert into tb_Notes(NoteId,Name) values(" + dr["Vendor_InspVisit_XmissionStructures_NoteId"] + ",'" + dr["Name"] + "') "));
            }

            return listQueries;


        }

        public static List<ENote> GetByResultId(string connectionString, Int32 resultId)
        {

            DataTable _dt = DInspectionNote.SelectAll(resultId, connectionString).Tables[0];

            List<ENote> _NoteList = new List<ENote>();
            foreach (DataRow dr in _dt.Rows)
            {
                ENote _note = new ENote(ConvertHelper.ToInt32(dr["Vendor_InspVisit_XmissionStructures_NoteFk"]), ConvertHelper.Tostring(dr["Note_Name"]));
                _note.InspectionResult = new EInspectionResult();
                _note.InspectionResult.Id = ConvertHelper.ToInt32(dr["Vendor_InspVisit_XmissionStructures_ResultFk"]);
                _NoteList.Add(_note);
            }
            return _NoteList;
        }

        public static DataSet GetNotesByInspectionResult(Int32 resultId,string connectionKey)
        {
            return DInspectionNote.SelectAll(resultId, connectionKey);
        }

        private static List<ENote> ParseDatatableNote(DataTable _dt)
        {
            List<ENote> _NoteList = new List<ENote>();
            foreach (DataRow dr in _dt.Rows)
            {
                ENote _note = new ENote(ConvertHelper.ToInt32(dr["Vendor_InspVisit_XmissionStructures_NoteFk"]), ConvertHelper.Tostring(dr["Note_Name"]));
                _NoteList.Add(_note);
            }
            return _NoteList;
        }

        public static void DeleteByInspectionResult(Int32 resultId, string connectionKey)
        {
            DInspectionNote.DeleteByInspectionResult(resultId,connectionKey);
        }

        public static Int32 Insert(Int32 noteId, Int32 resultId, string connectionKey)
        {
            return DInspectionNote.Insert(noteId, resultId, connectionKey);
        }
    }
}
